<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>V-for 中的ref动态引用</title>
</head>

<body>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="Application">

    <div v-for="(item, i) in list" :ref="el=>{divs[i]=el}">
      {{i}}-{{item}}
    </div>
  </div>
  <script>
    const App = Vue.createApp({
      setup() {
        const list = Vue.reactive([1, 2, 3]);
        const divs = Vue.ref([]);
        console.log("打印下看看有啥", divs.value)
        //数据更新前
        Vue.onBeforeUpdate(() => {
          //确保在每次更新之前重置参考。
          divs.value = [];
        })
        Vue.onMounted(() => {
          console.log("DOM加载完毕后打印：", divs.value)
        })

        return {
          list,
          divs,
        };
      },
    });
    App.mount("#Application");
  </script>
</body>

</html>